package com.llw.notify.mail_sender;

import java.util.HashMap;

public class EmailServer {
    public enum ServiceProvider {
        NETEASE_126,
        NETEASE_163,
        QQ,
        Unknown,
    }

    // 在这里设置SMTP邮件服务提供商的SMTP主机地址
    private static final HashMap<ServiceProvider, String> hostMap = new HashMap<ServiceProvider, String>() {{
        put(ServiceProvider.NETEASE_126, "smtp.126.com");
        put(ServiceProvider.NETEASE_163, "smtp.163.com");
        put(ServiceProvider.QQ, "smtp.qq.com");
        put(ServiceProvider.Unknown, "unknown");
    }};
    // 在这里设置SMTP邮件服务器的 端口号
    private static final HashMap<ServiceProvider, String> portMap = new HashMap<ServiceProvider, String>() {{
        put(ServiceProvider.NETEASE_126, "25");
        put(ServiceProvider.NETEASE_163, "25");
        put(ServiceProvider.QQ, "25");
        put(ServiceProvider.Unknown, "-1");
    }};

    public static ServiceProvider getEmailServerType(final String emailAddress) {
        if (emailAddress.endsWith("@163.com")) {
            return ServiceProvider.NETEASE_163;
        }
        else if (emailAddress.endsWith("@126.com")) {
            return ServiceProvider.NETEASE_126;
        }
        else if (emailAddress.endsWith("@qq.com")) {
            return ServiceProvider.QQ;
        }
        else {
            return ServiceProvider.Unknown;
        }
    }

    public static String getEmailHost(final String emailAddress) {
        return getEmailHost(getEmailServerType(emailAddress));
    }

    public static String getEmailHost(final ServiceProvider emailServerType) {
        return hostMap.get(emailServerType);
    }

    public static String getEmailServerPort(final String emailAddress) {
        return getEmailServerPort(getEmailServerType(emailAddress));
    }

    public static String getEmailServerPort(final ServiceProvider emailServerType) {
        return portMap.get(emailServerType);
    }
}
